<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .income_box {
        	height: 70px;
        	line-height: 70px;
        	padding: 0 15px;
        	display: -webkit-box;
        	display: -webkit-flex;
        	background-color: #fff;
        }
        .income_box .income_boxl {
        	color: #999;
        	font-size: 14px;
        }
        .income_box .income_boxr {
        	flex: 1;
        	-webkit-flex: 1;
        	box-flex: 1;
        	-webkit-box-flex: 1;
        	text-align: right;
        	color: #e62442;
        	padding-left: 5px;
        	font-size: 19px;
        	overflow: hidden;
        	text-overflow: ellipsis;
        	white-space: nowrap;
        }
        .title_p {
        	height: 35px;
        	line-height: 41px;
        	color: #333;
        	font-size: 12px;
        	padding: 0 15px;
        }
        .main {
        	background-color: #fff;
        }
        .main ul li .li_box {
        	height: 50px;
        	line-height: 50px;
        	border-bottom: 1px solid #e8e8e8;
        	display: -webkit-box;
        	display: -webkit-flex;
        	align-items: center;
        	padding: 0 15px;
        }
        .main ul li:last-child .li_box {
        	border-bottom: none;
        }
        .main ul li .li_box .li_boxl {
        	width: 0;
        	flex: 1;
        	-webkit-flex: 1;
        	box-flex: 1;
        	-webkit-box-flex: 1;
        	padding-right: 10px;
        	color: #333;
        	font-size: 15px;
        	overflow: hidden;
        	text-overflow: ellipsis;
        	white-space: nowrap;
        }
        .main ul li .li_box .li_boxr {
        	display: -webkit-box;
        	-webkit-box-align: center;
        }
        .main ul li .li_box .li_boxr span {
        	display: block;
        	margin-right: 10px;
        	font-size: 12px;
        	color: #999;
        }
        .main ul li .li_box .li_boxr img {
        	height: 13px;
        	display: block;
        }
    </style>
</head>
<body id="aaa">
	<div class="income_box">
		<div class="income_boxl">本周累计收入</div>
		<div class="income_boxr">RM<span class="week_income"></span></div>
	</div>
	<div class="title_p">提现记录</div>
    <div class="main">
    	<ul id="recordC">
    		<!-- <li tapmode onclick="fnWithdrawalsDetail();">
    			<div class="li_box">
    				<div class="li_boxl">7月21日-7月25日</div>
    				<div class="li_boxr">
    					<span>RM419</span>
    					<img src="../image/right.png">
    				</div>
    			</div>
    		</li>
    		<li tapmode onclick="fnWithdrawalsDetail();">
    			<div class="li_box">
    				<div class="li_boxl">7月21日-7月25日</div>
    				<div class="li_boxr">
    					<span>RM419</span>
    					<img src="../image/right.png">
    				</div>
    			</div>
    		</li>
    		<li tapmode onclick="fnWithdrawalsDetail();">
    			<div class="li_box">
    				<div class="li_boxl">7月21日-7月25日</div>
    				<div class="li_boxr">
    					<span>RM419</span>
    					<img src="../image/right.png">
    				</div>
    			</div>
    		</li>
    		<li tapmode onclick="fnWithdrawalsDetail();">
    			<div class="li_box">
    				<div class="li_boxl">7月21日-7月25日</div>
    				<div class="li_boxr">
    					<span>RM419</span>
    					<img src="../image/right.png">
    				</div>
    			</div>
    		</li> -->
    	</ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script id="recordL" type="text/x-dot-template">
    {{ for (var i = 0; i < it.length; i++) { }}
        <li tapmode onclick="fnWithdrawalsDetail({{=it[i]['id']}});">
            <div class="li_box">
                <div class="li_boxl">{{=it[i]['week_time']}}</div>
                <div class="li_boxr">
                    <span>RM{{=it[i]['amount']}}</span>
                    <img src="../image/right.png">
                </div>
            </div>
        </li>
    {{ }; }}
</script>

<script type="text/javascript">

    var p = 1; // 默认第一页
    var canLoad = false; // 默认不可上拉加载更多
    
    apiready = function(){
        staffData = $api.getStorage('staff_data');
        getWeekIncome();
        getWeekRecord();

        // 下拉刷新
        api.setCustomRefreshHeaderInfo({
            bgColor: '#f8f8f8',
            loadAnimInterval:60,
            image: {
               pull: pullArr,
               load: loadArr
            }
        }, function(ret, err) {
            p = 1;
            canLoad = false;
            getWeekIncome(1);
            getWeekRecord(1);
        });

        // 上拉加载
        api.addEventListener({
            name:'scrolltobottom',
            extra:{
                threshold:0            //设置距离底部多少距离时触发，默认值为0，数字类型
            }
        }, function(ret, err){
            if(canLoad == true){
                canLoad = false;
                var _dom = $api.byId('recordC');
                setLoadingData(_dom);
                getWeekIncome(2);
                getWeekRecord(2);
            }
        });
    };

    function getWeekRecord (t) {
        api.ajax({
            url: rootPath + '/api/staff/get_week_record',
            method: 'post',
            data: {
                values: { 
                    staff_id: staffData.id,
                    staff_token: staffData.token,
                    p: p
                },
            }
        }, function(ret, err) {
            if(ret.status == 200){
                if(t == 2){
                    appendDotData (ret.data,'recordL','recordC',true);
                }else{
                    setDotData (ret.data,'recordL','recordC',true);
                }
                if(ret.data.length == 10){
                    p++;
                    canLoad = true;
                }else{
                    canLoad = false;
                }
            }else{
                if(p == 1){
                    // 首次获取就无订单
                    var _dom = $api.byId('recordC');
                    setWithoutData(_dom,'暂无数据','#f8f8f8','70');
                    canLoad = false;
                }
            }
            if(t == 1){
                api.refreshHeaderLoadDone();
            }
            if(p > 1){
                hideLoadingData();
            }
        });
    };

    function getWeekIncome (t) {
        api.ajax({
            url: rootPath + '/api/staff/get_week_income',
            method: 'post',
            data: {
                values: { 
                    staff_id: staffData.id,
                    staff_token: staffData.token,
                },
            }
        }, function(ret, err) {
            if(ret.status == 200){
                if(ret.data){
                    $(".week_income").html(ret.data);
                }
            }
            if(t == 1){
                api.refreshHeaderLoadDone();
            }
        });
    };

    // 提现详情
    function fnWithdrawalsDetail(_id) {
        api.openWin({
            name: 'withdrawals_detail',
            url: './withdrawals_detail.html',
            pageParam:{
                id: _id
            }
        });
    }



</script>
</html>